package com.living.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.living.R;
import com.md.basedpc.PHSizeUtils;

public class ImgLoadUtils {

    /**
     * @param context
     * @param img
     * @param url
     */
    public static void disPlayCircle(Context context, ImageView img, String url) {
        disPlayCircle(context, img, url, R.drawable.icon_player_audio_pic);
    }

    /**
     * @param context
     * @param img
     * @param url
     */
    public static void disPlayRound(Context context, ImageView img, String url) {
        disPlayRound(context, img, url, R.drawable.icon_player_audio_pic);
    }


    /**
     * @param img
     * @param url
     * @param defaultImage
     */
    public static void disPlayCircle(Context context, ImageView img, String url, int defaultImage) {
        RequestOptions requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .circleCrop()
                .error(defaultImage)
                .placeholder(defaultImage);
        if (TextUtils.isEmpty(url)) url = "";
        RequestManager requestManager = Glide.with(context);
        requestManager.load(url).apply(requestOptions).into(img);
    }

    /**
     * @param img
     * @param url
     * @param defaultImage
     */
    public static void disPlayRound(Context context, ImageView img, String url, int defaultImage) {
        RoundedCorners roundedCorners = new RoundedCorners(PHSizeUtils.mm2px(context, 12));
        RequestOptions requestOptions = new RequestOptions()
                .transform(roundedCorners)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .error(defaultImage)
                .placeholder(defaultImage);
        if (TextUtils.isEmpty(url)) url = "";
        RequestManager requestManager = Glide.with(context);
        requestManager.load(url).apply(requestOptions).into(img);
    }



}
